#!/usr/bin/env python2
# coding: utf-8


import unittest
from zstack import Client
from zstack.controller import cluster

ADMIN_USERNAME = 'admin'
ADMIN_PASSWORD = 'password'
ZSTACK_API_URL = 'http://192.168.1.115:8080/zstack/api'
# 115服务器上cluster相关参数
CLUSTER_UUID = '4378fb5cd2834ed99b78e9c4e0ef660e'
CLUSTER_NAME = 'CLUSTER-1'
CLUSTER_STATE = 'Enabled'
CLUSTER_TYPE = 'zstack'


class TestCluster(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.client = Client(ADMIN_USERNAME, ADMIN_PASSWORD, ZSTACK_API_URL)
        cls.client.login()

    def test_query_cluster(self):
        # 查询全部集群
        cls = cluster.query_cluster(self.client)
        self.assertIn(CLUSTER_UUID, [cl.get('uuid') for cl in cls])

        # 根据uuid查询单个集群
        cls1 = cluster.query_cluster_by_uuid(self.client, CLUSTER_UUID)
        self.assertIn(CLUSTER_NAME, [cl.get('name') for cl in cls1])
        self.assertIn(CLUSTER_STATE, [cl.get('state') for cl in cls1])
        self.assertIn(CLUSTER_TYPE, [cl.get('type') for cl in cls1])

if __name__ == '__main__':
    unittest.main()
